// pages/activity/group_exchange/main_page/my_group/my_group.js
var app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  attached: function() {
    //初始化页面顶部的bar
    this.initBarOptions();
    //初始化scrolllist
    this.initScrollList();
    this.setData({
      groupListHeight: app.globalData.pageHeight - 220,
    })
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /**
     * 初始化头部栏
     */
    initBarOptions: function (order_type) {
      var options = {
        item: {
          width: 250,
          height: 88,
          size: 30,
          color: '#999999',
          selectedColor: '#1f1f1f',
        },
        slider: {
          width: 90,
          color: '#1f1f1f',
        },
        data: [{
          name: '全部',
          id: 0,
          type: null,
        }, {
          name: '待领取  ',
          id: 1,
          type: 1,
        }, {
          name: '已领取',
          id: 2,
          type: 2,
        }]
      };
      this.setData({
        navbarOptions: options
      })
    },

    /**
     * 初始化列表
     */
    initScrollList: function (order_status) {
      var orderOptions = {
        list_id: 'group_list',
        url: '/api/index.php?app=group&act=my_spell_group',
        data: {
          order_status: order_status
        }
      }
      this.setData({
        orderOptions: orderOptions
      })
    },

    /**
     * 头部切换
     */
    navbarClick: function (e) {
      //设置当前的订单类型
      this.initScrollList(e.detail.type);
    },

    /**
     * 加载数据
     */
    loadMoreData: function (e) {
      if (e.detail.data.length > 0) {
        for (let item of e.detail.data) {
          item.quantity = 1;
          item.sell_price = item.sku_sell_price;
          item.goods_attr_arr = item.sku_attr;
        }
      }
      // console.log(e.detail.data);
      this.setData({
        groupList: e.detail.data,
      })
    },

    /**
     * 查看订单详情
     */
    lookGroupInfo: function (e) {
      var index = e.currentTarget.dataset.index;
      var groupInfo = this.data.groupList[index];
      wx.navigateTo({
        url: '../group_info/group_info?spell_group_id=' + groupInfo.group_id,
      })
    },

    /**
     * 跳转到拼团首页
     */
    goMainpage: function() {
      this.triggerEvent('switch', {index:0}, {})
    },

    /**
     * 领取商品 
     */
    takeGoods: function (e) {
      var index = e.currentTarget.dataset.index;
      var groupInfo = this.data.groupList[index];
      wx.navigateTo({
        url: '../../../goods/receive_info/receive_info?order_id=' + groupInfo.order_id,
      })
    },

    /**
     * 查看订单 
     */
    checkOrderInfo: function (e) {
      var index = e.currentTarget.dataset.index;
      var groupInfo = this.data.groupList[index];
      wx.navigateTo({
        url: '../../../../pages/goods/exchanged_info/exchanged_info?order_id=' + groupInfo.order_id,
      })
    }
  }
})
